<template>
  <el-cascader
    siez="mini"
    :value="value"
    :options="data"
    :props="props"
    separator="-"
    placeholder="请选择部门"
    @change="hChange"
  />
</template>

<script>
import { getDepartment } from '@/api/department'
import { arr2tree } from '@/utils'
export default {
  props: {
    value: {
      type: [Number, String],
      required: true
    }
  },
  data() {
    return {
      data: [],
      props: {
        value: 'id',
        label: 'name',
        emitPath: false
      }
    }
  },
  created() {
    this.loadDepartment()
  },
  methods: {
    async loadDepartment() {
      const res = await getDepartment()
      this.data = arr2tree(res.data, 0)
    },
    hChange(value) {
      // console.log(value)
      // const id = value.at(-1)
      this.$emit('input', value)
    }
  }
}
</script>

<style>

</style>
